package util;

import java.util.StringTokenizer;

public class SequencePredeterminee implements Sequence {

	public final static String NOMBRE_SEQUENCE_PROPERTY_NAME = "sim.sequence.predeterminee";
	private int[] sequence;
//	private static ThreadLocal<Integer> actualIndex = new ThreadLocal<>();
	private int actualIndex = 0;
	public SequencePredeterminee() {
		String stringSequence = SimProperties.getInstance().getStringProperty(
				NOMBRE_SEQUENCE_PROPERTY_NAME);
		StringTokenizer tokenizer = new StringTokenizer(stringSequence);
		int count = tokenizer.countTokens();
		sequence = new int[count];

		for (int i = 0; i < count; i++) {
			sequence[i] = Integer.parseInt(tokenizer.nextToken());
		}
	}

	@Override
	public int nextNumber() {
//		if(actualIndex.get()==null){
//			actualIndex.set(0);
//		}

		int retVal;
//		int index= actualIndex.get();
		//retVal = sequence[actualIndex];
		retVal = sequence[actualIndex];

		// On recommence la séquence lorsqu'on a terminé.
		if (++actualIndex >= sequence.length) {
//		actualIndex.set(++index);
//		if (index >= sequence.length) {

			actualIndex = 0;
			//reset();
		}
		return retVal;
	}
	
//	public static void reset()
//	{
//		//actualIndex = 0;
//		actualIndex.set(0);
//	}

}
